import { defineStore } from 'pinia'
import { AdPositionType, Region, Lang } from '@/enums'
import { getBannerList } from '@/api/betting'
// import { bannersReq } from '@/api/casino'
import { AdInfo } from '@/types'

export const useADStore = defineStore('ad', {
	state: () => ({
		loginList: [] as Array<AdInfo>,
		feedList: [] as Array<AdInfo>,
		tournamentList: [] as Array<AdInfo>,
		sportsList: [] as Array<AdInfo>,
		slotsList: [] as Array<AdInfo>,
		casinoList: [] as Array<AdInfo>
	}),
	actions: {
		async getADList(type: AdPositionType, region: Region, language: Lang) {
			try {
				const { data } = await getBannerList(type, region, language)
				switch (type) {
					case AdPositionType.login:
						this.setLoginList(data)
						break
					case AdPositionType.feed:
						this.setFeedList(data)
						break
					case AdPositionType.tournament:
						this.setTournamentList(data)
						break
					case AdPositionType.sports:
						this.setSportsList(data)
						break
					case AdPositionType.slots:
						this.setSlotsList(data)
						break
					case AdPositionType.casino:
						this.setCasinoList(data)
						break
				}
			} catch (error) {}
		},
		setLoginList(val: []) {
			this.loginList = val
		},
		setFeedList(val: []) {
			this.feedList = val
		},
		setTournamentList(val: []) {
			this.tournamentList = val
		},
		setSportsList(val: []) {
			this.sportsList = val
		},
		setSlotsList(val: []) {
			this.slotsList = val
		},
		setCasinoList(val: []) {
			this.casinoList = val
		}
	},
	getters: {
		getListByType: (state) => {
			return (type: AdPositionType) => {
				switch (type) {
					case AdPositionType.login:
						return state.loginList
					case AdPositionType.feed:
						return state.feedList
					case AdPositionType.tournament:
						return state.tournamentList
					case AdPositionType.sports:
						return state.sportsList
					case AdPositionType.slots:
						return state.slotsList
					case AdPositionType.casino:
						return state.casinoList
				}
			}
		}
	}
})
